<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/22/022
 * Time: 18:00
 */

namespace app\api\model;


class Admin extends BaseModel {

    /**
     * 链接管理员日志模型
     * 一对多
     * @return \think\model\relation\HasMany
     */
    function adminLog() {
        return $this->hasMany('AdminLog', 'admin_id', 'id');
    }

    /**
     * 根据用户名获取管理员
     * @param $username
     * @return array|null|\PDOStatement|string|\think\Model
     */
    public static function getAdminByUsername($username) {
        $admin = self::where('username', '=', $username)->find();
        return $admin;
    }

    /**
     * 获取管理员列表
     * @param array $where
     * @return \think\Paginator
     */
    public static function getList($where = []) {
        $list = self::where($where)->order('id desc')->paginate();
        return $list;
    }

    /**
     * 根据ID获取管理员信息
     * @param $id
     * @return static
     */
    public static function getAdminById($id) {
        $admin = self::get($id);
        return $admin;
    }
}